package com.team.abs.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.team.abs.service.UploadService;

@Controller
public class UploadController {
	  @Autowired
	    private UploadService uploadService;
	
	  //后端处理上传图片
	    @PostMapping("/image")
	    public  ResponseEntity<String> uploadImage(MultipartHttpServletRequest request) throws IOException {
	    	MultipartFile file = request.getFile("file");
	        String resultUrl;
	        byte[] bytes = file.getBytes();
	        resultUrl = uploadService.uploadImage( bytes, ".png");
	        return ResponseEntity.ok(resultUrl);
	    }
}
